package ivan.cheng.activitys;

import ivan.cheng.R;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;
import android.widget.TextView;

import com.umeng.analytics.MobclickAgent;
import com.umeng.update.UmengUpdateAgent;

public class MainActivity extends TabActivity{
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.tab);
		UmengUpdateAgent.update(this);
		UmengUpdateAgent.setUpdateOnlyWifi(false);
		MobclickAgent.onError(this);
		TabHost tabs = getTabHost();
		
		
		
		TabHost.TabSpec spec = tabs.newTabSpec("number");
		spec.setIndicator(createTabIndicator(R.drawable.top_btn_selector,
				R.string.tab_title_number));
		// spec.setIndicator(res.getText(R.string.tab_title_mode),
		// res.getDrawable(R.drawable.setting_btn_selector));
		spec.setContent(new Intent().setClass(this, PermissionByNumberActivity.class));
		tabs.addTab(spec);
		
		spec = tabs.newTabSpec("catagory");
		spec.setIndicator(createTabIndicator(
				R.drawable.mantain_btn_selector,
				R.string.tab_title_catagory));
		spec.setContent(new Intent()
				.setClass(this, PermissionManagerActivity.class));
		tabs.addTab(spec);
		
		spec = tabs.newTabSpec("level");
		spec.setIndicator(createTabIndicator(R.drawable.setting_btn_selector,
				R.string.tab_title_level));
		spec.setContent(new Intent().setClass(this,
				PermissionLevelActivity.class));
		tabs.addTab(spec);
		
		

		spec = tabs.newTabSpec("more");
		View v = createTabIndicator(R.drawable.more_btn_selector,
				R.string.tab_title_more);
		spec.setIndicator(v);

		spec.setContent(new Intent().setClass(this, MoreInfoActivity.class));
		tabs.addTab(spec);
		tabs.setCurrentTab(0);
	}



	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
	}

	private View createTabIndicator(int iconResId, int titleResId) {
		View view = LayoutInflater.from(this).inflate(R.layout.tab_item, null);
		// ImageView iv = (ImageView)view.findViewById(R.id.tab_icon);
		view.setBackgroundResource(iconResId);
		TextView tv = (TextView) view.findViewById(R.id.tab_title);
		// ImageView iv = (ImageView)view.findViewById(R.id.tab_icon);

		// iv.setImageResource(iconResId);
		tv.setText(titleResId);
		// iv.setBackgroundResource(iconResId);

		return view;
	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
	}
	
//	class MyTabHost extends TabHost {
//
//		private boolean isOpenAnimation = false;
//		private Animation slideLeftIn;
//		private Animation slideLeftOut;
//		private Animation slideRightIn;
//		private Animation slideRightOut;
//		private int mTabCount = 0;
//
//		public MyTabHost(Context context) {
//			super(context);
//			slideLeftIn = AnimationUtils.loadAnimation(context,
//					R.anim.i_slide_in_left);
//			slideRightIn = AnimationUtils.loadAnimation(context,
//					R.anim.i_slide_in_right);
//			slideLeftOut = AnimationUtils.loadAnimation(context,
//					R.anim.i_slide_out_left);
//			slideRightOut = AnimationUtils.loadAnimation(context,
//					R.anim.i_slide_out_right);
//		}

//		@Override
//		public void setCurrentTab(int index) {
//			int mCurrentTabID = getCurrentTab();
//			if (null != getCurrentView()) {
//				// 第一次设置 Tab 时，该值为 null。
//				if (isOpenAnimation) {
//					if (mCurrentTabID == (mTabCount - 1) && index == 0) {
//						getCurrentView().startAnimation(slideLeftOut);
//					} else if (mCurrentTabID == 0 && index == (mTabCount - 1)) {
//						getCurrentView().startAnimation(slideRightOut);
//					} else if (index > mCurrentTabID) {
//						getCurrentView().startAnimation(slideLeftOut);
//					} else if (index < mCurrentTabID) {
//						getCurrentView().startAnimation(slideRightOut);
//					}
//				}
//			}
//			super.setCurrentTab(index);
//			if (isOpenAnimation) {
//				if (mCurrentTabID == (mTabCount - 1) && index == 0) {
//					getCurrentView().startAnimation(slideLeftIn);
//				} else if (mCurrentTabID == 0 && index == (mTabCount - 1)) {
//					getCurrentView().startAnimation(slideRightIn);
//				} else if (index > mCurrentTabID) {
//					getCurrentView().startAnimation(slideLeftIn);
//				} else if (index < mCurrentTabID) {
//					getCurrentView().startAnimation(slideRightIn);
//				}
//			}
//		}
//
//		@Override
//		public void addTab(TabSpec tabSpec) {
//			super.addTab(tabSpec);
//			mTabCount++;
//		}
//
//	}

}